// pages/my/myOrder/myOrder.js
import Dialog from '@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userId: 0,
    orderList: [],
  },

  onDelImg: function (event) {
    console.log(event.currentTarget.dataset.orderid)
    Dialog.confirm({
      message: '确定删除所选订单？删除不可恢复',
    }).then(() => {
      wx.request({
        url: `http://localhost:8080/hotel/hotelOrder/${event.currentTarget.dataset.orderid}`,
        method: 'delete',
        header: {
          Authorization: getApp().globalData.authorization
        },
        success: (resp) => {
          console.log(resp)
        }
      })
    })
    .catch(() => {
      // on cancel
    })
  },

  onCancel: function (event) {
    Dialog.confirm({
      message: '确定取消所选订单吗？取消不可恢复',
    }).then(() => {
      wx.request({
        url: `http://localhost:8080/hotel/hotelOrder/${event.currentTarget.dataset.orderid}`,
        method: 'delete',
        header: {
          Authorization: getApp().globalData.authorization
        },
        success: (resp) => {
          console.log(resp)
        }
      })
      location.reload()
    })
    .catch(() => {
      // on cancel
    })
  },

  getUserId() {
    // 查询用户id
    var loginfo = getApp().globalData.loginfo;
    console.log(loginfo)
    this.setData({
      userId: loginfo.userId
    })
  },

  getHotelOrderByUserId() {
    wx.request({
      url: 'http://localhost:8080/hotel/hotelOrder/list',
      method: 'get',
      header: {
        Authorization: getApp().globalData.authorization
      },
      data: {
        userId: this.data.userId,
      },
      success: (resp) => {
        console.log(resp)
        this.setData({
          orderList: resp.data.rows
        })
        console.log("ol", this.data.orderList)
      }
    })
  },
/**
 * 生命周期函数--监听页面加载
 */
onLoad(options) {
  this.getUserId()
  this.getHotelOrderByUserId()
},

/**
 * 生命周期函数--监听页面初次渲染完成
 */
onReady() {

},

/**
 * 生命周期函数--监听页面显示
 */
onShow() {

},

/**
 * 生命周期函数--监听页面隐藏
 */
onHide() {

},

/**
 * 生命周期函数--监听页面卸载
 */
onUnload() {

},

/**
 * 页面相关事件处理函数--监听用户下拉动作
 */
onPullDownRefresh() {
  wx.pageScrollTo({ scrollTop: 0, duration: 0 })
},

/**
 * 页面上拉触底事件的处理函数
 */
onReachBottom() {

},

/**
 * 用户点击右上角分享
 */
onShareAppMessage() {

}
})